/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [Example_05_Manager_Test.java]
 * Creation Date        [17-Jun-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_02_oop;

/**
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Example_05_Manager_Test {

	/**
	 * 测试方法
	 * 
	 * @param args
	 *            命令行参数
	 */
	public static void main(String[] args) {
		Example_05_Manager manager = new Example_05_Manager("Cloud", 30000,
				2011, 8, 20);
		manager.setBonus(20000);

		Example_01_Employee[] staff = new Example_01_Employee[3];
		staff[0] = manager; // 多态
		// staff[0].setBonus(20000);根据多态性:父类引用不能调用子类中新增加的方法
		staff[1] = new Example_01_Employee("Sean", 20000, 2011, 6, 20);
		staff[2] = new Example_01_Employee("Yang", 10000, 2011, 6, 20);

		/**
		 * 如果子类不重写toString()方法, 父类的getSalary方法将会被调用
		 */
		for (Example_01_Employee employee : staff) {
			System.out.println(employee);
		}

		System.out.println("============");
		SuperClass subClass = new SubClass(3);
		// 下面的代码输出了103, 原因在于在调用Super类的构造方法时, 由于多态, this其实是子类对象,
		// 因此调用的是子类的setId的方法
		System.out.println(subClass.getId());
		SuperClass superClass = new SuperClass(3);
		System.out.println(superClass.getId());
	}

}

/**
 * 父类
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 */
class SuperClass {

	private int id;

	public SuperClass(int id) {
		this.setId(id);
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}
}

/**
 * 子类
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 */
class SubClass extends SuperClass {

	public SubClass(int id) {
		super(id);
		this.setId(id);
	}

	@Override
	public void setId(int id) {
		super.setId(id + 100);
	}
}
